
using Abp.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;


namespace SOEI.Solution.DomainEntities.RoomSourceVerifiy.DomainService
{
    /// <summary>
    /// 领域服务层一个模块的核心业务逻辑
    ///</summary>
    public class RoomVerifyManager : DomainServiceBase, IRoomVerifyManager
    {

        private readonly IRepository<RoomVerify, long> _roomverifyRepository;

        /// <summary>
        /// 【RoomVerify】的构造方法
        /// 通过构造函数注册服务到依赖注入容器中
        ///</summary>
        public RoomVerifyManager(IRepository<RoomVerify, long> roomverifyRepository)
        {
            _roomverifyRepository = roomverifyRepository;
        }

        #region -------------------------------------------------辅助工具生成---------------------------------------------- 

        /// <summary>
        /// 返回列表查询用
        /// </summary>
        /// <returns></returns>
        public IQueryable<RoomVerify> QueryEntityListAsNoTracking()
        {

            var query = _roomverifyRepository.GetAll().AsNoTracking()
                        .Select(x => new RoomVerify
                        {
                            Id = x.Id,
                            CertificateCode = x.CertificateCode,
                            CertificateName = x.CertificateName,
                            StateCode = x.StateCode,
                            Remark = x.Remark,
                            CreationTime = x.CreationTime,
                            CreatorUserId = x.CreatorUserId,
                            LastModificationTime = x.LastModificationTime,
                            LastModifierUserId = x.LastModifierUserId
                        });
            return query;
        }

        /// <summary>
        /// 【RoomVerify】返回表达式数的实体信息即IQueryable类型
        /// </summary>
        /// <returns>IQueryable</returns>
        public IQueryable<RoomVerify> Query()
        {
            return _roomverifyRepository.GetAll();
        }
        /// <summary>
        /// 【RoomVerify】返回即IQueryable类型的实体，不包含EF Core跟踪标记
        /// </summary>
        /// <returns>IQueryable</returns>
        public IQueryable<RoomVerify> QueryAsNoTracking()
        {
            return _roomverifyRepository.GetAll().AsNoTracking();
        }
        /// <summary>
        /// 【RoomVerify】根据Id查询实体信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns>实体</returns>
        public async Task<RoomVerify> FindByIdAsync(long id)
        {
            var entity = await _roomverifyRepository.GetAsync(id);
            return entity;
        }
        /// <summary>
        /// 【RoomVerify】检查实体是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns>bool</returns>
        public async Task<bool> IsExistAsync(long id)
        {
            var result = await _roomverifyRepository.GetAll().AnyAsync(a => a.Id == id);
            return result;
        }
        /// <summary>
        /// 【RoomVerify】创建实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<RoomVerify> CreateAsync(RoomVerify entity)
        {
            entity.Id = await _roomverifyRepository.InsertAndGetIdAsync(entity);
            return entity;
        }
        /// <summary>
        /// 【RoomVerify】更新实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task UpdateAsync(RoomVerify entity)
        {
            await _roomverifyRepository.UpdateAsync(entity);
        }
        /// <summary>
        /// 【RoomVerify】删除实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteAsync(long id)
        {
            //TODO:删除前的逻辑判断，是否允许删除
            await _roomverifyRepository.DeleteAsync(id);
        }
        /// <summary>
        /// 【RoomVerify】批量删除
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task BatchDelete(List<long> input)
        {
            //TODO:删除前的逻辑判断，是否允许删除
            await _roomverifyRepository.DeleteAsync(a => input.Contains(a.Id));
        }
        #endregion


        #region -------------------------------------------------用户自定义------------------------------------------------
        /*请在此扩展领域服务接口*/

        /// <summary>
        /// 判断指定的产权证编号是否存在
        /// </summary>
        /// <param name="CertificateCode"></param>
        /// <returns></returns>
        public async Task<bool> IsExistAsync(string CertificateCode)
        {
            var result = await _roomverifyRepository.GetAll().AnyAsync(a => a.CertificateCode == CertificateCode);
            return result;
        }

        /// <summary>
        /// 【RoomVerify】根据产权号CertificateCode查询实体信息
        /// </summary>
        /// <param name="CertificateCode"></param>
        /// <returns>实体</returns>
        public async Task<RoomVerify> FindByCertificateCodeAsync(string CertificateCode)
        {
            var entity = await _roomverifyRepository.GetAll().Where(a => a.CertificateCode == CertificateCode).FirstOrDefaultAsync();
            return entity;
        }
        #endregion









    }
}
